<?php

class Produk{

    var $db;

    public function __construct(){
        $this->db = new DBClass();
    }
    
    public function get_all_pro(){ 
        $query = "Select * from produk";
        $rows = $this->db->getRows($query);
        return $rows;
    }

    public function del_pro(){
        $sql = "DELETE FROM produk WHERE idproduk = '".$_GET['idproduk']."'"; 
        $rows = $this->db->putRows($sql);
        return $rows;
    }

    public function add_pro(){
        $sql = "INSERT INTO produk SET nama = '".$_POST['nama']."',
                                       kategori = '".$_POST['kategori']."',
                                       stok = ".$_POST['stok'].",
                                       harga = '".$_POST['harga']."',
                                       deskripsi = '".$_POST['deskripsi']."',
                                       img = 'template/bootstrap/img/".$_POST['img']."'";
                                       
        $rows = $this->db->putRows($sql);
        return $rows;
    }

    public function edit_pro(){
        $sql = "UPDATE produk SET nama = '".$_POST['nama']."',
                                  kategori = '".$_POST['kategori']."',
                                  stok = ".$_POST['stok'].",
                                  harga = '".$_POST['harga']."',
                                  deskripsi = '".$_POST['deskripsi']."' WHERE idproduk = '".$_GET['idproduk']."'";
        $rows = $this->db->putRows($sql);
        return $rows;
    }
    public function show_order(){
        $sql = "SELECT * FROM pesan e JOIN produk r ON e.idproduk = r.idproduk JOIN member m ON e.idmember = m.idmember Order By idpesan";
        $rows = $this->db->getRows($sql);
        return $rows;
    }

    public function del_order(){
        $sql = "DELETE FROM pesan WHERE idpesan = '".$_GET['idpesan']."'"; 
        $rows = $this->db->putRows($sql);
        return $rows;
    }

    public function edit_order(){
        $sql = "UPDATE pesan SET status = '".$_POST['status']."' WHERE idpesan = '".$_GET['idpesan']."'";
        $rows = $this->db->putRows($sql);
        return $rows;
    }


}
?>